
#
#Given a linked list, determine if it has a cycle in it.
#

# @author:timlentse(tinglenxan@gmail.com)
# @Date: 2014-11-19

# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    # @param head, a ListNode
    # @return a boolean
    def hasCycle(self, head):
        if not head:
            return False
        else:
            node = head
            while(node.next != head)and(node.next != None):
                node = node.next
            return True if node.next == None else False